#!/bin/bash
# filename: mysql_replication_check.sh

# 检测IO线程状态
io_status=$(mysql -e "SHOW SLAVE STATUS\G" 2>/dev/null | grep "Slave_IO_Running" | awk '{print $2}')

# 检测SQL线程状态
sql_status=$(mysql -e "SHOW SLAVE STATUS\G" 2>/dev/null | grep "Slave_SQL_Running" | awk '{print $2}')

# 输出IO状态
if [ "$io_status" = "Yes" ]; then
    echo "IO状态: 1"
else
    echo "IO状态: 0"
fi

# 输出SQL状态
if [ "$sql_status" = "Yes" ]; then
    echo "SQL状态: 1"
else
    echo "SQL状态: 0"
fi
